#pragma once
#include <atomic>
#include <thread>
#include <functional>
#include <chrono>
#include <iostream>

class RateMonitor
{
public:
    using Callback = std::function<void(uint64_t recvRate, uint64_t sendRate)>;

    RateMonitor();
    ~RateMonitor();

    void start();
    void stop();

    void incRecv(); // 收到一个订单时调用
    void incSend(); // 发出一个订单时调用

    void setCallback(Callback cb);

private:
    void run();

    std::atomic<uint64_t> recvCounter_{0};
    std::atomic<uint64_t> sendCounter_{0};
    std::atomic<bool> running_{false};

    std::thread thread_;
    Callback callback_;
};
